const conn = require('../../libs/DB/Conn');
const operationRecord = require("../sys/operationRecordAction");

module.exports = async function (params) {
    let checkUserSql = `SELECT
                            count(*) AS count
                        FROM
                            user_file uf
                        WHERE user_id != ?
                            AND login_name = ? 
                            AND delete_sign = 1
                        ;`;

    let queryResult = await conn(checkUserSql, [params.userId,params.loginName]);
    if (queryResult[0].count > 0) {
        return {success: false, message: '此登录名已存在，请重新输入登录名'};
    } else {
        let updateObj = {
            login_name:params.loginName,
            user_name:params.userName,
            mobile:params.mobile
        };
        let updateSql = `update user_file SET ? WHERE user_id = ?`;
        await conn(updateSql, [updateObj, params.userId]);
        await operationRecord(params);
        return {success: true, message: '修改成功'}
    }
};